package com.haier.npt.authention.support;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.haier.npt.common.JsonResult;
import com.haier.npt.exception.BizBaseException;
import com.haier.npt.security.client.SysRoleClient;
import com.haier.npt.security.domain.SysPermission;

@Component
public class PermissionSupport {
	
	private static final Logger logger = LoggerFactory.getLogger(PermissionSupport.class);
	
	@Autowired
	private SysRoleClient  sysRoleClient ; 
	
	
	public List<SysPermission> listPermissionByUserId(Long userId, String token){
		List<SysPermission>  permissions = new ArrayList<>(); 
		//获取当前登录人的权限
		JsonResult<List<SysPermission>> jsonResult = sysRoleClient.listPermissionByUserId(userId,token);
		if(jsonResult.getCode() ==0){
			permissions.addAll(jsonResult.getData());
		}else{
			//异常的话这里记录下日志
			logger.error("获取权限失败 ,  租户编号{0} 用户编号{1} ,异常信息 {2}", userId , jsonResult);
			throw new BizBaseException(jsonResult);
		}
		return permissions ; 
	}
	
	
	
}
